import service from '@/utils/request'

// 创建表单
export const createForm = (data) => {
  return service({
    url: '/intelligent-form/form/create',
    method: 'post',
    data
  })
}

// 更新表单
export const updateForm = (data) => {
  return service({
    url: '/intelligent-form/form/update',
    method: 'put',
    data
  })
}

// 删除表单
export const deleteForm = (params) => {
  return service({
    url: '/intelligent-form/form/delete',
    method: 'delete',
    params
  })
}

// 获取表单详情
export const getForm = (params) => {
  return service({
    url: '/intelligent-form/form/detail',
    method: 'get',
    params
  })
}

// 获取表单列表
export const getFormList = (params) => {
  return service({
    url: '/intelligent-form/form/list',
    method: 'get',
    params
  })
}

// 发布表单
export const publishForm = (data) => {
  return service({
    url: '/intelligent-form/form/publish',
    method: 'post',
    data
  })
}

// 关闭表单
export const closeForm = (data) => {
  return service({
    url: '/intelligent-form/form/close',
    method: 'post',
    data
  })
}

// 获取公开表单（不需要认证）
export const getPublicForm = (id, password = '') => {
  return service({
    url: `/intelligent-form/public/form/${id}`,
    method: 'get',
    params: { password },
    skipAuth: true  // 跳过认证
  })
}

// 提交表单（不需要认证）
export const submitForm = (data) => {
  return service({
    url: '/intelligent-form/public/submit',
    method: 'post',
    data,
    skipAuth: true  // 跳过认证
  })
}

// 获取提交记录列表
export const getSubmissionList = (params) => {
  return service({
    url: '/intelligent-form/submission/list',
    method: 'get',
    params
  })
}

// 获取提交记录详情
export const getSubmission = (params) => {
  return service({
    url: '/intelligent-form/submission/detail',
    method: 'get',
    params
  })
}

// 删除提交记录
export const deleteSubmission = (params) => {
  return service({
    url: '/intelligent-form/submission/delete',
    method: 'delete',
    params
  })
}

// 导出提交数据为Excel
export const exportSubmissions = (params) => {
  return service({
    url: '/intelligent-form/submission/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 获取生成的表单（不需要认证）
export const getGeneratedForm = (id, password = '') => {
  return service({
    url: `/intelligent-form/generated/form/${id}`,
    method: 'get',
    params: { password },
    skipAuth: true  // 跳过认证
  })
}

// 提交生成的表单（不需要认证）
export const submitGeneratedForm = (data) => {
  return service({
    url: '/intelligent-form/generated/submit',
    method: 'post',
    data,
    skipAuth: true  // 跳过认证
  })
} 